'abusize.monkey by Belimoth
Strict
Import abucomponent
'TODO
'	autoAlign:Int?
'	increasing the size should have some physics behavior response

Public

Const ALIGN_MIDDLE:Int = 0
Const ALIGN_LEFT:Int = 1		'--01
Const ALIGN_RIGHT:Int = 2		'--10
Const ALIGN_TOP:Int = 4			'01--
Const ALIGN_BOTTOM:Int = 8		'10--

Const DIRECTION_NORTH:Int = 0
Const DIRECTION_EAST:Int = 1
Const DIRECTION_SOUTH:Int = 2
Const DIRECTION_WEST:Int = 3



Interface ISize
	Method Width:Int() Property
	Method Width:Void(widthNew:Int) Property
	Method SetWidth:Void(widthNew:Int, align:Int = ALIGN_LEFT)
	Method Height:Int() Property
	Method Height:Void(heightNew:Int) Property
	Method SetHeight:Void(heightNew:Int, align:Int = ALIGN_TOP)
	Method SetSize:Void(widthNew:Int, heightNew:Int, align:Int = ALIGN_LEFT|ALIGN_TOP)
	Method GetEdge:Int(direction:Int)
End



Class SizeComponent Extends EntityComponent<ISize> Implements ISize

Public
	Method Width:Int() Property Return _width End
	Method Width:Void(widthNew:Int) Property SetWidth(widthNew) End
	Method Height:Int() Property Return _height End
	Method Height:Void(heightNew:Int) Property SetHeight(heightNew) End
	
	Method SetWidth:Void(widthNew:Int, align:Int = ALIGN_LEFT)
		If widthNew = _width Then Return
		If align & ALIGN_LEFT
			'TODO
		Elseif align & ALIGN_RIGHT
			'TODO
		Else	'ALIGN_MID
			'TODO
		End
		_width = widthNew
	End
	
	Method SetHeight:Void(heightNew:Int, align:Int = ALIGN_TOP)
		If heightNew = _height Then Return
		If align & ALIGN_TOP
			'TODO
		Elseif align & ALIGN_BOTTOM
			'TODO
		Else	'ALIGN_MID
			'TODO
		End
		_height = heightNew
	End
	
	Method SetSize:Void(widthNew:Int, heightNew:Int, align:Int = ALIGN_LEFT|ALIGN_TOP)
		SetWidth(widthNew, align)
		SetHeight(heightNew, align)
	End
	
	Method GetEdge:Int(direction:Int)
		Select direction
			Case DIRECTION_NORTH
				Return owner.Position.Y
			Case DIRECTION_SOUTH
				Return owner.Position.Y + _height - 1
			Case DIRECTION_EAST
				Return owner.Position.X
			Case DIRECTION_WEST
				Return owner.Position.X + _width - 1
			Default
		End
		Return 0
	End
	
Private
	Field _width:Int
	Field _height:Int
End